package com.shlh.saas.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.shlh.saas.entity.RechargeRecord;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 充值记录Mapper接口
 */
@Mapper
public interface RechargeRecordMapper extends BaseMapper<RechargeRecord> {
    
    /**
     * 查询用户的交易记录
     * @param phone 用户手机号
     * @param type 交易类型，可为null表示查询所有类型
     * @return 交易记录列表
     */
    @Select("<script>" +
            "SELECT * FROM recharge_records WHERE phone = #{phone} " +
            "<if test='type != null and type != \"\"'> AND recharge_type = #{type} </if>" +
            "ORDER BY created_at DESC" +
            "</script>")
    List<RechargeRecord> selectUserRecords(@Param("phone") String phone, @Param("type") String type);
    
    /**
     * 根据订单号查询充值记录
     * @param orderNo 订单号
     * @return 充值记录
     */
    @Select("SELECT * FROM recharge_records WHERE order_no = #{orderNo} LIMIT 1")
    RechargeRecord selectByOrderNo(@Param("orderNo") String orderNo);
} 